package student.aistar.day13;

import java.io.*;

/**
 * 语法糖 - JVM去关闭流 - 最终的版本
 */
public class StreamAutoCloserDemo {
    public static void main(String[] args) {
        //自动关闭这些资源
        try(BufferedInputStream in = new BufferedInputStream(new FileInputStream("C:\\Users\\qinfeng\\Pictures\\广西美食\\images2.jpg"));
            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("C:\\Users\\qinfeng\\Pictures\\广西美食\\images5.jpg"))){
            //自定义一个byte[]
            byte[] buf = new byte[3*1024];

            int len = -1;

            while(true){
                len = in.read(buf);
                if(len==-1)
                    break;
                out.write(buf,0,len);
            }
            System.out.println("文件拷贝成功!");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
